﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Linq.Expressions;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;
using ASPItalia.ModelVirtualCasting.Parts;

namespace ASPItalia.ModelVirtualCasting.Fake
{
    [Export("ModelRepository", typeof(IModelRepository))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    [RepositoryMetadata(Name = "ModelRepository", IsFake = true)]
    public class ModelRepository : BaseRepository<IModelRepository>, IModelRepository
    {
        protected List<Model> List = new List<Model>();

        public ModelRepository()
        {
            Model model = new Model();
            model.NickName = "Patricia";
            model.BirthDate = new DateTime(1985, 1, 1);
            model.NationalityCountry = new Country { CountryName = "U.S.A." };
            List.Add(model);

            model = new Model();
            model.NickName = "Carla";
            model.BirthDate = new DateTime(1984, 1, 1);
            model.NationalityCountry = new Country { CountryName = "Italia" };
            List.Add(model);

            model = new Model();
            model.NickName = "Monika";
            model.BirthDate = new DateTime(1982, 1, 1);
            model.NationalityCountry = new Country { CountryName = "Russia" };
            List.Add(model);

            model = new Model();
            model.NickName = "Claire";
            model.BirthDate = new DateTime(1988, 1, 1);
            model.NationalityCountry = new Country { CountryName = "Francia" };
            List.Add(model);
        }

        public void InsertOnSubmit(Model entity)
        {
        }

        public void Update(Model entity)
        {
        }

        public void DeleteOnSubmit(Model entity)
        {
        }

        public void SubmitChanges()
        {
        }

        public IQueryable<ModelDTO> GetRandomModels(int number)
        {
            string imageUrl = "default.png";

            var query = from m in this.List
                        select new ModelDTO()
                        {
                            Age = DateTime.Today.Year - m.BirthDate.Year,
                            Country = m.NationalityCountry.CountryName,
                            ImageUrl = imageUrl,
                            NickName = m.NickName
                        };

            return query.AsQueryable();
        }

        public IQueryable<Model> GetAll()
        {
            return null;
        }

        public IQueryable<Model> Where(Expression<Func<Model, bool>> predicate)
        {
            return null;
        }

        public long Count(Expression<Func<Model, bool>> predicate)
        {
            return 0L;
        }

        public IModelRepository EnableLazyLoading()
        {
            return this;
        }

        public IModelRepository DisableLazyLoading()
        {
            return this;
        }

        public IModelRepository Include(string path)
        {
            return this;
        }


				public IModelRepository Include<TProperty>(Expression<Func<Model, TProperty>> path)
				{
					return this;
				}

				public IModelRepository CreateQuery()
				{
					return this;
				}

				public IModelRepository DoNotTrack()
				{
					return this;
				}
		}
}
